{% extends "base.html" %}
{% block title %}Dss系统初始化{% endblock %}
{% block content_header %}
    <h1>
      系统初始化
      <small>sso server setup</small>
    </h1>
{% endblock %}

{% block content %}
<div class="box box-info">
    <div class="box-header with-border">
        <h3 class="box-title">配置初始化信息</h3><i class="fa fa-fw fa-question-circle" title="初始化帮助"  
            data-container="body" data-toggle="popover" data-placement="top" 
            data-content="请填写<认证ldap地址>,<ldap基础dn>,<管理员账号>,<密码>,<sso系统管理员账号>(注意格式,用逗号分隔),<cookie有效期>(单位小时,可不填,默认10小时),<单点登录子域名>(如.calmkart.com)"></i>
    </div>
    <!-- /.box-header -->
    <!-- form start -->
    <form class="form-horizontal">
        <div class="box-body">
            <div class="form-group">
                <div class="col-sm-2"></div>
                <label for="inputEmail3" class="col-sm-2 control-label">ldap host</label>
                <div class="col-sm-4">
                    <input class="form-control" id="host" placeholder="ldap://ldap.calmkart.com:389" type="text">
                </div>
                <div class="col-sm-4"></div>
            </div>
            <div class="form-group">
                <div class="col-sm-2"></div>
                <label for="inputEmail3" class="col-sm-2 control-label">ldap base dn</label>
                <div class="col-sm-4">
                    <input class="form-control" id="basedn" placeholder="ou=people,dc=calmkart,dc=com" type="text">
                </div>
                <div class="col-sm-4"></div>
            </div>
            <div class="form-group">
                <div class="col-sm-2"></div>
                <label for="inputEmail3" class="col-sm-2 control-label">ldap admin</label>
                <div class="col-sm-4">
                    <input class="form-control" id="admin" placeholder="cn=admin,dc=calmkart,dc=com" type="text">
                </div>
                <div class="col-sm-4"></div>
            </div>
            <div class="form-group">
                <div class="col-sm-2"></div>
                <label for="inputEmail3" class="col-sm-2 control-label">ldap pass</label>
                <div class="col-sm-4">
                    <input class="form-control" id="password" placeholder="password!@#" type="text">
                </div>
                <div class="col-sm-4"></div>
            </div>
            <div class="form-group">
                <div class="col-sm-2"></div>
                <label for="inputEmail3" class="col-sm-2 control-label">系统管理员账号</label>
                <div class="col-sm-4">
                    <input class="form-control" id="sys_admin" placeholder="pengng,calmkart,admin" type="text">
                </div>
                <div class="col-sm-4"></div>
            </div>
            <div class="form-group">
                <div class="col-sm-2"></div>
                <label for="inputEmail3" class="col-sm-2 control-label">cookie有效期(选填,单位小时,默认10小时)</label>
                <div class="col-sm-4">
                    <input class="form-control" id="timeout" placeholder="10" type="number">
                </div>
                <div class="col-sm-4"></div>
            </div>
            <div class="form-group">
                <div class="col-sm-2"></div>
                <label for="inputEmail3" class="col-sm-2 control-label">单点登录子域名(选填)</label>
                <div class="col-sm-4">
                    <input class="form-control" id="domain" placeholder=".calmkart.com" type="text">
                </div>
                <div class="col-sm-4"></div>
            </div>
        </div>
    </form>
        <!-- /.box-body -->
        <div class="box-footer">
            <button type="submit" class="btn btn-info pull-right" onclick="setup_submit()">开始初始化系统</button>
        </div>
        <!-- /.box-footer -->
</div>
{% endblock %}

{% block footer_js %}
<script>
    $(function () { 
        $("[data-toggle='popover']").popover();
    });

    function setup_submit(){
        var ldap_url = $("#host").val();
        var basedn = $("#basedn").val();
        var admin = $("#admin").val();
        var password = $("#password").val();
        var sys_admin = $("#sys_admin").val();
        var timeout = $("#timeout").val();
        var domain = $("#domain").val();
        var data = JSON.stringify({
            "ldap_url":ldap_url, 
            "basedn":basedn, 
            "admin":admin, 
            "password":password, 
            "sys_admin":sys_admin,
            "timeout":timeout,
            "domain":domain,
        });
        $.ajax({
            url: "{% url 'start' %}",
            type: 'POST',
            dataType: "json",
            data: data,
            async: true,
            success: function(msg) {
                if (msg["status"]===false){
                    bootbox.alert({
                        title: "初始化失败",
                        message: msg["msg"]
                    });
                }
                else{
                    bootbox.alert({
                        title: "初始化成功",
                        message: "系统初始化成功,点击确认跳转至登录界面",
                        callback: function(){ 
                            window.location.href = "/login/";
                        }
                    })
                }
                
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                bootbox.alert({
                    title: "初始化失败",
                    message: msg["msg"]
                })
            }
        });
    };
</script>

{% endblock %}










